import { validatePhoneTwo } from '@/utils/validate'
/* 是否金额 2位小数点*/
export const isMoneyTwo = (rule, value, callback) => {
  const reg = /^(0|[1-9]\d*)(\.\d{1,2})?$/
  if (value == '' || value == undefined || value == null) {
    callback()
  } else {
    if (!reg.test(value)) {
      callback(new Error('请输入合法的金额数字，最多两位小数'))
    } else {
      callback()
    }
  }
}
/* 是否金额 8位小数点 非必定*/
export const isMoneyEightNot = (rule, value, callback) => {
  const reg = /^(0|[1-9]\d*)(\.\d{1,8})?$/
  if (value == '' || value == undefined || value == null) {
    callback()
  } else {
    if (!reg.test(value)) {
      callback(new Error('请输入合法的金额数字，最多八位小数'))
    } else {
      callback()
    }
  }
}
/* 是否金额 8位小数点 -必填*/
export const isMoneyEight = (rule, value, callback) => {
  const reg = /^(0|[1-9]\d*)(\.\d{1,8})?$/
  if (!reg.test(value)) {
    callback(new Error('请输入合法的金额数字，最多八位小数'))
  } else {
    callback()
  }
}
// 新增商机表单规则
export const formRules = {
  customerName: [
    { required: true, message: '客户名称不能为空', trigger: ['blur', 'change'] }
  ],
  customerTaxcode: [
    { required: true, message: '税号不能为空', trigger: ['blur', 'change'] }
  ],
  taxAuthorityId: [
    {
      required: true,
      message: '主管税务机关不能为空',
      trigger: ['blur', 'change']
    }
  ],
  customerIndustry: [
    { required: true, message: '客户行业不能为空', trigger: ['blur', 'change'] }
  ],
  customerGenre: [
    { required: true, message: '客户类型不能为空', trigger: ['blur', 'change'] }
  ],
  attnName: [
    {
      required: true,
      message: '联系人不能为空',
      trigger: ['blur', 'change']
    }
  ],
  attnPhone: [
    {
      required: true,
      validator: validatePhoneTwo,
      trigger: ['blur', 'change']
    }
  ],
  contactName: [
    {
      required: true,
      message: '客户联系人不能为空',
      trigger: ['blur', 'change']
    }
  ],
  contactPhone: [
    {
      required: true,
      validator: validatePhoneTwo,
      trigger: ['blur', 'change']
    }
  ],
  resource: [
    { required: true, message: '商机来源不能为空', trigger: ['blur', 'change'] }
  ],
  status: [
    { required: true, message: '商机状态不能为空', trigger: ['blur', 'change'] }
  ],
  projectType: [
    { required: true, message: '项目类型不能为空', trigger: ['blur', 'change'] }
  ],
  titleName: [
    { required: true, message: '商机标题不能为空', trigger: ['blur', 'change'] }
  ],
  belongId: [
    { required: true, message: '归属人员不能为空', trigger: ['blur', 'change'] }
  ],
  revenue: [
    {
      required: false,
      message: '',
      trigger: ['blur', 'change']
    },
    {
      validator: isMoneyEightNot
    }
  ]
}
